﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;

namespace Ajc {
    public partial class AllowedUsersForm : Form {
        public AllowedUsersForm(StringCollection allowedUsers, List<SkypeContact> contacts) {
            InitializeComponent();

            this.allowedUserGroup.Enabled = Ajc.Properties.Settings.Default.allowedUsersEnabled;
         
            foreach (SkypeContact contact in contacts)
            {
                bool isChecked = allowedUsers.Contains(contact.Handle);
                this.allowedUserList.Items.Add(contact, isChecked);
            }
        }

        /// <summary>
        /// Gets the the user in the text box as an string array.
        /// </summary>
        public StringCollection AllowedUsers
        {
            get {
                StringCollection newAllowedUsers = new StringCollection();
                foreach (SkypeContact item in this.allowedUserList.CheckedItems)
                {
                    newAllowedUsers.Add(item.Handle);
                }

                return newAllowedUsers;
            }
        }

        public bool AllowedUsersEnabled
        {
            get
            {
                return this.enableAllowedUsers.Checked;
            }
        }


        private void enableAllowedUsers_CheckedChanged(object sender, EventArgs e) {
            this.allowedUserGroup.Enabled = this.enableAllowedUsers.Checked;
        }

        private void close_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

    }
}
